/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AramaIslemleri.java
 *
 * Created on 28.Ara.2011, 13:13:22
 */
package oopdesignpatternsproject;

import commands.SearchCommander;
import entityclasses.Session;
import javax.swing.DefaultListModel;
import entityclasses.SocialApp;
import entityclasses.Person;

/**
 *
 * @author YCAN
 */
public class AramaIslemleri extends javax.swing.JFrame {

    /** Creates new form AramaIslemleri */
    String aranan;

    public AramaIslemleri(String aranan) {
        initComponents();
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.aranan = aranan;

        listArkadaslar.setModel(new SearchCommander(aranan, Session.currentUser.getProfile().getFriends()).getResult());
        listTumu.setModel(new SearchCommander(aranan, SocialApp.instance().getRegisteredPersons()).getResult());
    }

    public AramaIslemleri() {
        initComponents();
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        listArkadaslar = new javax.swing.JList();
        jLabel2 = new javax.swing.JLabel();
        btnIstekGonder = new javax.swing.JButton();
        btnProfiliGor = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        listTumu = new javax.swing.JList();
        btnProfiliGor1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel1.setText("Arkadaş Listesi Sonuçları");
        jLabel1.setName("jLabel1"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        listArkadaslar.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listArkadaslar.setName("listArkadaslar"); // NOI18N
        jScrollPane2.setViewportView(listArkadaslar);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel2.setText("Tüm Sonuçlar");
        jLabel2.setName("jLabel2"); // NOI18N

        btnIstekGonder.setFont(new java.awt.Font("Tahoma", 1, 11));
        btnIstekGonder.setForeground(new java.awt.Color(0, 204, 102));
        btnIstekGonder.setText("İstek Gönder");
        btnIstekGonder.setName("btnIstekGonder"); // NOI18N
        btnIstekGonder.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnIstekGonderMouseClicked(evt);
            }
        });

        btnProfiliGor.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnProfiliGor.setForeground(new java.awt.Color(255, 0, 51));
        btnProfiliGor.setText("Profili Göster");
        btnProfiliGor.setName("btnProfiliGor"); // NOI18N
        btnProfiliGor.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnProfiliGorMouseClicked(evt);
            }
        });

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        listTumu.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listTumu.setName("listTumu"); // NOI18N
        jScrollPane1.setViewportView(listTumu);

        btnProfiliGor1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnProfiliGor1.setForeground(new java.awt.Color(255, 0, 51));
        btnProfiliGor1.setText("Profili Göster");
        btnProfiliGor1.setName("btnProfiliGor1"); // NOI18N
        btnProfiliGor1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnProfiliGor1MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(btnIstekGonder)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 168, Short.MAX_VALUE)
                        .addComponent(btnProfiliGor))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 198, Short.MAX_VALUE)
                        .addComponent(btnProfiliGor1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(btnProfiliGor1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnIstekGonder)
                    .addComponent(btnProfiliGor))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btnIstekGonderMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnIstekGonderMouseClicked

    Session.currentUser.addAsFriend((Person) listTumu.getSelectedValue());
}//GEN-LAST:event_btnIstekGonderMouseClicked

private void btnProfiliGorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnProfiliGorMouseClicked

    int durum;
    Person selectedOne = (Person) listTumu.getSelectedValue();
    if (Session.currentUser.getProfile().getFriends().contains(selectedOne)) {
        durum = 0;
    } else {
        durum = 1;
    }

    ProfilBilgisiGoster pbg = new ProfilBilgisiGoster(selectedOne, durum);
    pbg.setVisible(true);
    pbg.setLocationRelativeTo(null);
}//GEN-LAST:event_btnProfiliGorMouseClicked

private void btnProfiliGor1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnProfiliGor1MouseClicked
    int durum;
    Person selectedOne = (Person) listArkadaslar.getSelectedValue();
    if (Session.currentUser.getProfile().getFriends().contains(selectedOne)) {
        durum = 0;
    } else {
        durum = 1;
    }

    ProfilBilgisiGoster pbg = new ProfilBilgisiGoster(selectedOne, durum);
    pbg.setVisible(true);
    pbg.setLocationRelativeTo(null);

}//GEN-LAST:event_btnProfiliGor1MouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AramaIslemleri.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AramaIslemleri.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AramaIslemleri.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AramaIslemleri.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new AramaIslemleri().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnIstekGonder;
    private javax.swing.JButton btnProfiliGor;
    private javax.swing.JButton btnProfiliGor1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JList listArkadaslar;
    private javax.swing.JList listTumu;
    // End of variables declaration//GEN-END:variables
}
